/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.venere.beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Entity Bean del Cliente
 * @author Venere
 */
@Entity(name="Cliente")
@Table(name="CLIENTE")
public class Cliente implements Serializable {
    private static final long serialVersionUID = 1L;
    
    private Long numCliente;
    private List<Conto> conti;
    private String nome, cognome, codFiscale;

    public Cliente() {
        super();
    }
    
    public Cliente(String nome, String cognome, String codFiscale) {
        super();
	this.setNome(nome);
	this.setCognome(cognome);
	this.setCodFiscale(codFiscale);
	this.setConti(new ArrayList<Conto>());
    }
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="NUMCLIENTE")
    public Long getNumCliente() {
        return numCliente;
    }

    public void setNumCliente(Long numCliente) {
        this.numCliente = numCliente;
    }

    @Column(name="NOME")
    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }
    
    @Column(name="COGNOME")
    public String getCognome() {
        return cognome;
    }

    public void setCognome(String cognome) {
        this.cognome = cognome;
    }

    @Column(name="CODFISCALE")
    public String getCodFiscale() {
        return codFiscale;
    }

    public void setCodFiscale(String codFiscale) {
        this.codFiscale = codFiscale;
    }

    @OneToMany(mappedBy="Conto")
    public List<Conto> getConti() {
        return conti;
    }

    public void setConti(List<Conto> conti) {
        this.conti = conti;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Cliente)) {
            return false;
        }
        Cliente other = (Cliente) object;
        if ((this.numCliente == null && other.numCliente != null) || 
                (this.numCliente != null && !this.numCliente.equals(other.numCliente))) {
            return false;
        }
        return true;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (numCliente != null ? numCliente.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        int y = 1;
        String stringaConti = null;
        Iterator<Conto> iteratorConti = conti.iterator();
        while (iteratorConti.hasNext()){
            Conto conto = iteratorConti.next();
            stringaConti = "N) " + y + " - " + conto.toString() + "\n";
            y++;
        }
        return "*** Cliente ***\nNumero: " + numCliente + "\nNome: " + getNome() +
        "\nCognome: " + getCognome() + "\nCodice Fiscale: " + getCodFiscale() +
        "\nConti: " + stringaConti;
    }
}
